#!/usr/bin/make -f
# -*- makefile -*-

# For the debian policies, see http://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules

export DH_VERBOSE=1

.PHONY: build-arch build-indep build build-stamp clean binary-indep binary-arch binary install configure configure-stamp


binary: binary-indep binary-arch
build: build-indep build-arch

# Configure the build
configure: configure-stamp
configure-stamp:
	dh_testdir
	# Configure
	mkdir --parents build && cd build && cmake .. -DTW_BUILD_ID='launchpad' -DCMAKE_INSTALL_PREFIX='/usr' -DCMAKE_BUILD_TYPE="RelWithDebInfo" && cd ..
	touch $@

# Build architecture-independent files
build-indep :

build-arch: build-stamp

# Build architecture-dependent files
build-stamp: configure-stamp  
	dh_testdir
	cd build && $(MAKE) VERBOSE=1
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -rf build build-stamp configure-stamp
	dh_clean 

# Build architecture-independent packages
binary-indep:
	dh_testdir
	dh_testroot
	dh_prep

	dh_installchangelogs
	dh_installdirs
	dh_installdocs

	# DON'T PACKAGE THE MANUAL IN EXPERIMENTAL BUILDS
	# Install the manual
#	mkdir --parents $(CURDIR)/debian/tmp/usr/share/doc/texworks-help/
#	cp -r manual $(CURDIR)/debian/tmp/usr/share/doc/texworks-help/TeXworks-manual

	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb



# Build architecture-dependent packages
binary-arch: build-stamp
	dh_testdir
	dh_testroot

	cd build && $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	dh_installchangelogs 
	dh_installdocs
	dh_install
	dh_installman
	dh_icons
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb


